<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.org/ui"
                xmlns:g="http://java.sun.com/jsf/composite/ezcomp"
                >

    <f:subview id="tutorialCadastroEmbutido" rendered="#{fluxoExibicaoTutorial.exibirCadastroTutorial}">
        <h:panelGrid columns="1" id="embPessCert" width="850" styleClass="center">
            <h:panelGroup id="groupCadTutorial" styleClass="esquerda">
                <h:form id="cadTutorialForm" styleClass="formularioFundo">
                    <h:panelGrid columns="4" styleClass="bvb-font">
                        <f:facet name="header">
                            <h:outputText value="#{msg.cadTutorialPanelGridTitle}" styleClass="formularioTitle"/>
                        </f:facet>
                        <h:outputLabel value="#{msg.titulo}:" id="labelTitulo" title="#{msg.titlteTituloTutorial}"/>
                        <p:inputText value="#{tutorialManager.tutorialCadastro.tituloTutorial}" id="tituloCad" required="true"
                                     requiredMessage="#{msg.campoObrigatorio}" title="#{msg.titlteTituloTutorial}"
                                     label="#{msg.titulo}" maxlength="90" size="80">
                            <f:validateLength minimum="10" maximum="90"/>
                        </p:inputText>
                        <g:help for="tituloHelp" helpText="#{msg.titlteTituloTutorial}"/>
                        <p:message for="tituloCad"/>

                        <h:outputLabel value="#{msg.url}:" id="labelUrl" title="#{msg.titleUrlTutorial}"/>
                        <p:inputText value="#{tutorialManager.tutorialCadastro.url}" id="urlCad" required="true"
                                     requiredMessage="#{msg.campoObrigatorio}" title="#{msg.titleUrlTutorial}"
                                     label="#{msg.url}" maxlength="300" size="80">
                            <f:validator validatorId="urlValidador"/>
                        </p:inputText>
                        <g:help for="urlHelp" helpText="#{msg.titleUrlTutorial}"/>
                        <p:message for="urlCad"/>

                        <h:outputLabel value="#{msg.indices}:" id="labelIndice" title="#{msg.titleIndiceTutorial}"/>
                        <p:inputText value="#{tutorialManager.tutorialCadastro.indice}" id="indiceCad" required="true"
                                     requiredMessage="#{msg.campoObrigatorio}" title="#{msg.titleIndiceTutorial}"
                                     label="#{msg.indices}" maxlength="100" size="80">
                            <f:validateLength minimum="3" maximum="100"/>
                        </p:inputText>
                        <g:help for="indeiceHelp" helpText="#{msg.titleIndiceTutorial}"/>
                        <p:message for="indiceCad"/>

                        <h:outputLabel value="#{msg.descricao}:" id="labelDescricao" title="#{msg.titleDescricaoTutorial}"/>
                        <p:inputTextarea value="#{tutorialManager.tutorialCadastro.descricao}" id="descricaoCad" required="true"
                                         requiredMessage="#{msg.campoObrigatorio}" title="#{msg.titleDescricaoTutorial}"
                                         label="#{msg.descricao}" cols="80" rows="3" maxLength="300" >
                            <f:validateLength minimum="10" maximum="300"/>
                        </p:inputTextarea>
                        <g:help for="descHelp" helpText="#{msg.titleDescricaoTutorial}"/>
                        <p:message for="descricaoCad"/>

                        <h:outputText value=""/>
                        <h:panelGroup id="buttonGroup">
                            <p:commandLink actionListener="#{tutorialManager.salvarTutorial()}" update="conteudoCentralGroup,messages"
                                           title="#{msg.titleButtonSalvarCadTutorial}" id="buttonSalvar" styleClass="ui-button_link">
                                <h:graphicImage library="img" name="bt_salvar.png"/>
                            </p:commandLink>
                            <p:spacer width="2" height="2"/>
                            <h:commandButton  title="#{msg.titleButtonCleanCadTutorial}" immediate="true" image="/resources/img/bt_limpar_red.png"
                                              id="buttonLimpar"  actionListener="#{tutorialManager.clean()}">
                                <f:ajax render="cadTutorialForm"></f:ajax>
                            </h:commandButton>
                        </h:panelGroup>
                    </h:panelGrid>
                </h:form>
            </h:panelGroup>

            <h:panelGroup id="spacers" styleClass="center">
                <p:spacer width="100%" height="5"/>
                <p:spacer width="100%" height="5"/>
            </h:panelGroup>

            <h:panelGroup id="tutorialTableGroup">
                <h:form id="formTableTutorial">
                    <p:dataTable value="#{tutorialManager.tutoriais}" var="tutorial"
                                 id="tableTutorial" rows="5" paginator="true" lazy="true"
                                 paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} 
                                 {CurrentPageReport} {NextPageLink} {LastPageLink}" paginatorPosition="top" 
                                 styleClass="bvb-font" rowsPerPageTemplate="5,10,20,30,50" 
                                 emptyMessage="#{msg.semRegistrosEcontrados}">
                        <f:facet name="header">
                            <h:outputText value="#{msg.richTableTutoriais}"/>
                        </f:facet>

                        <p:column id="col1" styleClass="center">
                            <f:facet name="header">
                                <h:outputText value="#{msg.titulo}"/>
                            </f:facet>
                            <h:outputText value="#{tutorial.tituloTutorial}"/>
                        </p:column>

                        <p:column id="col2" styleClass="center">
                            <f:facet name="header">
                                <h:outputText value="#{msg.url}"/>
                            </f:facet>
                            <h:outputLink value="#{tutorial.url}" target="_blank" title="#{tutorial.url}" styleClass="ui-button_link">
                                <h:graphicImage library="img" name="url.png"/>
                            </h:outputLink>
                        </p:column>

                        <p:column id="col4" styleClass="center">
                            <f:facet name="header">
                                <h:outputText value="#{msg.divulgadoPor}"/>
                            </f:facet>
                            <h:outputText value="#{tutorial.usuario.login}"/>
                        </p:column>

                        <p:column id="col5" styleClass="center" filterBy="#{tutorial.indice}">
                            <f:facet name="header">
                                <h:outputText value="#{msg.indices}"/>
                            </f:facet>
                            <h:outputText value="#{tutorial.indice}"/>
                        </p:column>

                        <p:column id="col6" styleClass="center">
                            <f:facet name="header">
                                <h:outputText value="#{msg.descricao}"/>
                            </f:facet>
                            <h:outputText value="#{tutorial.descricao}"/>
                        </p:column>

                        <p:column id="editar" styleClass="center">
                            <f:facet name="header">
                                <h:outputText value="#{msg.richColumnEditar}"/>
                            </f:facet>
                            <p:commandLink update="conteudoCentralGroup,messages" rendered="#{usuario_logado eq tutorial.usuario || loginManager.usuario.maxRole.papel.level >= 200}"
                                           id="buttonEditar" styleClass="ui-button_link">
                                <h:graphicImage library="img" name="tut_24_edit.png"/>
                                <f:setPropertyActionListener value="#{tutorial}" target="#{tutorialManager.tutorialCadastro}" />  
                            </p:commandLink>
                        </p:column>

                    </p:dataTable>
                </h:form>
            </h:panelGroup>
        </h:panelGrid>

    </f:subview>
</ui:composition>
